// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Rotating Spike Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 56 : TYPE_ROTATINGSPIKE

// Function declarations
reserve function RotatingSpike_DebugDraw
reserve function RotatingSpike_DebugSpawn

// Static Values
public value RotatingSpike_value32 = 0;

// Tables

function RotatingSpike_DebugDraw
	DrawSprite(0)
end function


function RotatingSpike_DebugSpawn
	CreateTempObject(TypeName[Rotating Spike], object.direction, object.xpos, object.ypos)
	temp0 = object[0].value17
	temp0 -= RotatingSpike_value32
	object[tempObjectPos].speed = 1
	object[tempObjectPos].speed <<= temp0
	if object.direction == FLIP_X
		object[tempObjectPos].angle = 256
	end if
end function


event ObjectMain
	object.angle -= object.speed
	if object.angle < 0
		object.angle += 512
	end if
	temp0 = object.xpos
	temp1 = object.ypos
	Cos(object.xpos, object.angle)
	object.xpos *= 0x2800
	object.xpos += temp0
	Sin(object.ypos, object.angle)
	object.ypos *= 0x2800
	object.ypos += temp1
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -16, -16, 16, 16, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		if checkResult == 1
			CallFunction(PlayerObject_Hit)
		end if
	next
	object.xpos = temp0
	object.ypos = temp1
end event


event ObjectDraw
	Cos(temp0, object.angle)
	temp0 *= 0x2800
	temp0 += object.xpos
	Sin(temp1, object.angle)
	temp1 *= 0x2800
	temp1 += object.ypos
	DrawSpriteXY(0, temp0, temp1)
end event


event ObjectStartup
	LoadSpriteSheet("SYZ/Objects.gif")
	SpriteFrame(-24, -24, 48, 48, 61, 178)
	foreach (TypeName[Rotating Spike], arrayPos0, ALL_ENTITIES)
		switch object[arrayPos0].propertyValue
		case 0
			object[arrayPos0].speed = 4
			break
		case 1
			object[arrayPos0].speed = 4
			object[arrayPos0].angle = 256
			break
		case 2
			object[arrayPos0].speed = 1
			break
		case 3
			object[arrayPos0].speed = 1
			object[arrayPos0].angle = 256
			break
		case 4
			object[arrayPos0].speed = 2
			break
		case 5
			object[arrayPos0].speed = 2
			object[arrayPos0].angle = 256
			break
		end switch
	next
	temp0 = 0
	RotatingSpike_value32 = DebugMode_ObjCount
	while temp0 < 3
		SetTableValue(TypeName[Rotating Spike], DebugMode_ObjCount, DebugMode_TypesTable)
		SetTableValue(RotatingSpike_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
		SetTableValue(RotatingSpike_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
		DebugMode_ObjCount++
		temp0++
	loop
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
